﻿using iPanel.DataProvider;
using SqlSugar;

namespace iPanel.Model;

public class OtlpResourceView
{
    private readonly OtlpResourceEntity entity;

    public OtlpResourceView(OtlpResourceEntity entity)
    {
        this.entity = entity;
    }
    public string NodeId => entity.NodeId;
    public string Ip => entity.Ip;
    public string State => entity.State;
    public string Cpu => string.Format("{0}%", entity.Cpu);
    public string DownTcp => string.Format("{0}{1}", toKb(entity.DownTcp).ToString("0.##"), "KB");
    public string ProcessDownTcp => string.Format("{0}{1}", toKb(entity.ProcessDownTcp).ToString("0.##"), "KB");
    public string ProcessMem => string.Format("{0}{1}", toMb(entity.ProcessMem).ToString("0.##"), "MB");
    public string UseDisk => string.Format("{0}{1}", toGB(entity.UseDisk).ToString("0.##"), "GB");
    public string TotalDisk => string.Format("{0}{1}", toGB(entity.TotalDisk).ToString("0.##"), "GB");
    public string UseMem => string.Format("{0}{1}", toGB(entity.UseMem).ToString("0.##"), "GB");
    public string TotalMem => string.Format("{0}{1}", toGB(entity.TotalMem).ToString("0.##"), "GB");
    public string UpTcp => string.Format("{0}{1}", toKb(entity.UpTcp).ToString("0.##"), "KB");
    public string ProcessUpTcp => string.Format("{0}{1}", toKb(entity.ProcessUpTcp).ToString("0.##"), "KB");
    public string AvailableDiskSpace => string.Format("{0}{1}", toGB(entity.AvailableDiskSpace).ToString("0.##"), "GB");
    public string AvailableMemory => string.Format("{0}{1}", toGB(entity.AvailableMemory).ToString("0.##"), "GB");
    public DateTime ModifyAt => entity.ModifyAt;

    public DateTime CreateAt => entity.CreateAt;
    double toKb(long v)
    {
        return v / 1024;
    }
    double toMb(long v)
    {
        return v / 1024 / 1024;
    }
    double toGB(long v)
    {
        return v / 1024 / 1024 / 1024;
    }
}
